from app import *
# ./mjpg_streamer \
# -i "./input_uvc.so --resolution 1920x1080 -d /dev/video2 -f 1 -q 100 -n" \
# -o "./output_file.so -f ../tmp"
def get_cam_fd():
    cmd='ls -l /dev/v4l/by-id/ |grep index0'
    res = shell_run(cmd)
    ret = '/dev/{}'.format(res.split('/')[-1].strip())
    return ret
def get_img_name():
    cmd="ls exe/tmp"
    ret=shell_run(cmd)
    return ret.strip()
def clean_pic():
    cmd="cd exe/tmp&& rm *.jpg"
    shell_run(cmd)
def take_picture():
    video_dev=get_cam_fd()
    cmd = "cd exe/build && ./mjpg_streamer -i './input_uvc.so --resolution 1920x1080 -d {} -f 1 -q 100 -n' -o './output_file.so -f ../tmp' >> /dev/null".format(video_dev)
    shell_run(cmd)
    pic_name = get_img_name()
    return pic_name
   

if __name__ == '__main__':
    file_name = take_picture()
    print(file_name)
    print("--------done----------")
    clean_pic()
    

